﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ConsoleApplication2
{
    public class MediaList : IDictionary<Media, int>
    {
        #region Fields
        private Dictionary<Media, int> _mediaList;
        #endregion

        #region Constructors
        public MediaList() 
        {
            this._mediaList = new Dictionary<Media, int>();
        }
        #endregion Constructors

        #region Properties
        public ICollection<Media> Keys
        {
            get { return _mediaList.Keys; }
        }

        public ICollection<int> Values
        {
            get { return _mediaList.Values; }
        }

        public int this[Media key]
        {
            get { return _mediaList[key]; }
            set { _mediaList[key] = value; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }
        #endregion

        #region Methods
        public void Add(Media key, int value)
        {
            if (value > 10)
                value = 10;
            if (value < 0)
                value = 0;

            if (this._mediaList.ContainsKey(key))
                this._mediaList[key] = value;
            else
                this._mediaList.Add(key, value);
        }

        public void Add(KeyValuePair<Media, int> item)
        {
            this.Add(item.Key, item.Value);
        }

        public bool Remove(Media key)
        {
            if (this._mediaList.ContainsKey(key))
                return this._mediaList.Remove(key);
            return false;
        }

        public bool Remove(KeyValuePair<Media, int> item)
        {
            return this.Remove(item.Key);
        }

        public bool ContainsKey(Media key)
        {
            if (_mediaList.ContainsKey(key))
                return true;
            return false;
        }

        public bool TryGetValue(Media key, out int value)
        {
            return _mediaList.TryGetValue(key, out value);
        }

        public void Clear()
        {
            this._mediaList.Clear();
        }

        public bool Contains(KeyValuePair<Media, int> item)
        {
            return this._mediaList.Contains(item);
        }

        public void CopyTo(KeyValuePair<Media, int>[] array, int arrayIndex)
        {
            this._mediaList.ToList().CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return this._mediaList.Count(); }
        }
        #endregion

        #region Enumerators
        public IEnumerator<KeyValuePair<Media, int>> GetEnumerator()
        {
            return _mediaList.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _mediaList.GetEnumerator();
        }
        #endregion
    }
}